package com.micookie.v2ex.model.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;
import com.micookie.v2ex.App;
import com.micookie.v2ex.R;

/**
 * Created by Administrator on 2016/10/27.
 */

public class Member implements Parcelable{


    private int id;
    @SerializedName("username")
    private String userName;
    @SerializedName("tagline")
    private String tagLine;
    @SerializedName("avatar_large")
    private String avatar;


    protected Member(Parcel in) {
        id = in.readInt();
        userName = in.readString();
        tagLine = in.readString();
        avatar = in.readString();
    }

    public Member() {

    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getTagLine() {
        return tagLine;
    }

    public void setTagline(String tagLine) {
        this.tagLine = tagLine;
    }


    public String getAvatar() {
        if (avatar == null || avatar.isEmpty()) {
            //// TODO: 2016/11/16 目前还有问题，返回的不能使用 
            return App.getInstance().getResources().getDrawable(R.drawable.default_avatar).toString();
        }

        if (avatar.startsWith("//")) return "http:" + avatar;

        return avatar;
    }

    public Member setAvatar(String avatar) {
        this.avatar = avatar;
        return this;
    }


    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(userName);
        dest.writeString(tagLine);
        dest.writeString(avatar);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<Member> CREATOR = new Creator<Member>() {
        @Override
        public Member createFromParcel(Parcel in) {
            return new Member(in);
        }

        @Override
        public Member[] newArray(int size) {
            return new Member[size];
        }
    };
}